-- card: 10571 from stack: in.3 -- bmap block id: 0 -- flags: 4000 -- background id: 8327 -- name: SerialHandler ----- HyperTalk script ----- on Install put ChooseTargetStack() into it InstallResource XFCN,SerialHandler,it end Install on opencard set the visible of button "put" to false set the visible of button "get" to false pass opencard end opencard -- part 3 (button) -- low flags: 00 -- high flags: 8003 -- rect: left=51 top=298 right=320 bottom=151 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: SerialHandler ----- HyperTalk script ----- on mouseUp get modaldialog(serialhandler,empty,cardCenter) if it is not "cancel" then set the visible of button "put" to true set the visible of button "get" to true end if end mouseUp -- part 5 (field) -- low flags: 01 -- high flags: 2007 -- rect: left=18 top=32 right=284 bottom=486 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 10 -- style flags: 0 -- line height: 13 -- part name: Documentation -- part 9 (button) -- low flags: 80 -- high flags: A003 -- rect: left=154 top=293 right=311 bottom=189 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Put ----- HyperTalk script ----- on mouseUp -- You may have to change the parameter list to suit your configuration -- NOTE: This button is a self contained operation of open, put,close. -- You DO NOT have to open and close every time you get or put. -- Just open once and start once, like when you open and close -- your stack. set the cursor to watch get SerialHandler("open","A",9600,8,none,1,"XON/XOFF") if it is not empty then put "Error: "&&it&&" (See script of "put" button)" end if put the number of lines in the script of me into nl repeat with i = 1 to nl get line i of the script of me get Serialhandler("put","A",it&return&numToChar(10)) end repeat if it is not empty then put "Error: "&&it end if get Serialhandler("close","A") end mouseUp -- part 10 (button) -- low flags: 80 -- high flags: 8003 -- rect: left=187 top=306 right=324 bottom=223 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Get ----- HyperTalk script ----- on mouseUp -- You may have to change the parameter list to suit your configuration -- NOTE: This button is a self contained operation of open, get,close. -- You DO NOT have to open and close every time you get or put. -- Just open once and start once, like when you open and close -- your stack. set the hilite of me to true set the cursor to watch get SerialHandler("open","A",9600,8,none,1,"XON/XOFF") set the visible of card field "got" to true put empty into card field "got" put "Click the mouse when done." put "Characters received on the serial port will appear below:" &return&return into card field "got" repeat while the mouse is up get SerialHandler("get","A",60) put it after card field "got" end repeat get SerialHandler("close","A") set the visible of card field "got" to false set the hilite of me to false put empty into msg hide msg end mouseUp -- part 11 (field) -- low flags: 81 -- high flags: 0007 -- rect: left=18 top=32 right=285 bottom=481 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: got -- part 12 (field) -- low flags: 01 -- high flags: 0004 -- rect: left=289 top=288 right=324 bottom=455 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: -- part contents for card part 5 ----- text ----- SerialHandler version 1.1a10 Roger Brown, Dartmouth College Serialhandler is a HyperCard XFCN that opens access to the Macintosh serial ports. Several functions are available through the one handler. Each is specified by an opcode in the first parameter. Successive parameters and the return value depend on the opcode. OPCODE INPUT DEFAULT OUTPUT ======= ===== ======= ======= "open " port (A,B) A = modem error messages baud (300-9600) 9600 if any, or the value of a handle data bits (5-8) 8 to the input buffer if parity (odd,even,none) none one larger than 64 stop bits (1,1.5,2) 1 bytes is requested flow control (XON/XOFF,CTS) XON/XOFF input buffer size 64 bytes "close" port (A,B) A = modem none input buffer (optional) "put" port (A,B) A = modem error messages source of characters none "get" port (A,B) A = modem error messages if any, timeout (ticks) 30 (1/2 sec) or characters received INVOKING SerialHandler get SerialHandler(task,port,...) where task is the opcode: open,close,put,or get port is the port to use ... other parameters as in the table above EXAMPLES 1. Opening with no parameters beyond the opcode will give you the defaults. ex. get SerialHandler("open") 2. If you want an input buffer larger than 64 bytes then you must declare a global variable to be used for only this purpose. Assign the return result of the open call to this global. The value of the global is the memory location of the large buffer. It will be locked until you close the serial port. It is very important that you do not change the value of this global and that you pass it back to SerialHandler in the " close" call before opening SerialHandler again. If you are using both ports, keep a separate buffer global for each. ex. On OpenPort global serialBufferA -- declare the global here put SerialHandler("open","A","4800,8,none,1,CTS,1024) into serialBufferA -- open the port and assign a 1024 byte buffer which is remembered in -- global serialBufferA end OpenPort on ClosePort global serialBufferA get SerialHandler("close","A",serialBufferA) -- close port, dispose the input -- buffer end closePort 3. When getting characters from the port, the timeout parameter is the minimum time that SerialHandler will wait for input. If there are still characters to be read at the end of the timeout period, SerialHandler will keep on reading until there are no more to be read. ex. put SerialHandler("get","A",60) into charsRecieved 4. get Serialhandler("put","A",the script of this stack) will send the text of the script out serial port A, assuming it has been opened. WARNING! If you attempt to open the printer port (port B) and get a return message of "Error opening serial port", open the Chooser and make sure that AppleTalk is INACTIVE! Just unplugging the network is not enough. REVISION HISTORY 1.0a0 7/5/88 alpha release 1.0a1 7/11/88 mistake in GetSerialChars - 1st call to SetGetBuff had AinRefNum instead of port as input 1.0a2 12/9/88 Call to ResultIs with an empty string was leaving orphan handles in the heap. Also, changed for compilation under LSC 3.0. 1.1a0 first non-public domain source version 1.1a7 9/1/89 Fixed bug in OpenSerial default handling that could cause random bus errors. 1.1a9 Fixed bug in the deallocation of memory if a buffer greater than 64K is used. Memory blocks were orphaned if there were multiple opens and closes in a single HyperCard session. 1.0a10 Won't bomb when called with no parameters at all. -- part contents for card part 12 ----- text ----- The source is not in the public domain, sorry. -- part contents for card part 11 ----- text ----- Characters received on the serial port will appear below: on mouseUp -- You may have to change the parameter list to suit your configuration -- NOTE: This button is a self contained operation of open, put,close. -- You DO NOT have to open and close every time you get or put. -- Just open once and start once, like when you open and close -- your stack. set the cursor to watch global gConfig --get SerialHandler("open","A",9600,8,none,1,"XON/XOFF") put "get SerialHandler(open,"&gConfig&")" into command do command put the result --get SerialHandler("open","A",9600,8,none,1,"XON/XOFF") if it is not empty then put "Error: "&&it&&" (See script of "put" button)" end if put the number of lines in the script of me into nl repeat with i = 1 to nl get line i of the script of me get Serialhandler("put","a",it&return&numToChar(10)) end repeat if it is not empty then put "Error: "&&it end if get Serialhandler("close","ab") end mouseUp